﻿using System;
using LocalizationUtils;
using LocalizationUtils.Utils;
using LocalizationUtils.Language;
using UnityEngine;
using UnityEngine.UI;

namespace LocalizationUtils
{
    [DisallowMultipleComponent]
    [RequireComponent(typeof(RectTransform))]
    [AddComponentMenu("UI/LocalizationUGIText", 11)]
    [ExecuteAlways]
    public class LocalizationUGUIText : Text, ILocalization
    {
        public bool _needAwake = true;
        public bool _arabicMultiLine = false; //阿拉伯语多行判断
        public long _key;
        private bool _localized;

        public override string text
        {
            get { return base.text; }
            set => this.SetUIText(value);
        }

        public long key
        {
            get => _key;
            set { _key = value; }
        }

        protected override void Awake()
        {
            base.Awake();
            if (Application.isPlaying && _needAwake)
            {
                if (_key == 0)
                    return;

                text = Lang.Get(_key);
            }

            this.SetArab(_arabicMultiLine);
        }
    }
}